package security.core.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.springframework.web.filter.GenericFilterBean;

import security.core.filter.handler.PrivilegeProcessHandler;
import security.core.manager.PrivilegeManager;
import security.debug.RBACLogger;

public class PrivilegeFilter extends GenericFilterBean {
	private PrivilegeManager privilegeManager;
	private PrivilegeProcessHandler privilegeProcessHandler;

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		if (RBACLogger.debug()) {
			RBACLogger.log("PrivilegeFilter#doFilter is called!");
		}
		privilegeProcessHandler.process(request, response, privilegeManager);
		chain.doFilter(request, response);
	}

	public void setPrivilegeManager(PrivilegeManager privilegeManager) {
		this.privilegeManager = privilegeManager;
	}

	public void setPrivilegeProcessHandler(
			PrivilegeProcessHandler privilegeProcessHandler) {
		this.privilegeProcessHandler = privilegeProcessHandler;
	}

}
